<?php
class Menu_Plugin_Breadcrumbs extends Zend_Controller_Plugin_Abstract {
	public function postDispatch(Zend_Controller_Request_Abstract $request) {
		if (! $request->isXmlHttpRequest () && (! $request->isDispatched () || $request->getControllerName () != "error")) {
			$cache = Zen_Cache_Factory::get('breadcrumbs');
			$url = $_SERVER ['REQUEST_URI'];
			$cache_id = "bread_" . md5 ( $url );
			$cont = $cache->load ( $cache_id );
			if (! $cont) {
				if (Zend_Registry::isRegistered ( 'activecont' )) {
					$cont = Zend_Registry::get ( 'activecont' );
					
					$cont = unserialize ( $cont );
					$cache->save ( $cont, $cache_id );
				}
			}
			if ($cont) {
				$layout = Zend_Layout::getMvcInstance ();
				$view = $layout->getView ();
				$view->navigation ( $cont );
				$bread = $view->navigation ()->breadcrumbs ()->setLinkLast ( true )->render ();
				if (mb_strlen ( $bread, "UTF-8" ) > 1) {
					$layout->assign ( 'breadcrumbs', '<div class="breadcrumbs">' . $bread . "</div>" );
				}
			
			}
		}
	}

}